package com.stockz.ui.swing.charting.callback;

import com.stockz.ui.swing.charting.display.screen.AbstractDisplayableScreenConfiguration;
import com.stockz.ui.swing.charting.util.RepaintStockChartPanelUtil;
import com.stockz.ui.swing.charting.view.StockChartPanel;
import com.stockz.ui.swing.widget.FilteredComboBox.OnSelectionCallback;

public class ChartingScreenNameSelectionCallback implements OnSelectionCallback {

	private final StockChartPanel stockChartPanel;
	
	public ChartingScreenNameSelectionCallback(StockChartPanel stockChartPanel) {
		this.stockChartPanel = stockChartPanel;
	}
	
	@Override
	public void onSelection(Object selectedItem) {
		AbstractDisplayableScreenConfiguration screen = 
			(AbstractDisplayableScreenConfiguration)selectedItem;
		if(stockChartPanel != null){
			stockChartPanel.getStockChartPanelState().getDisplayableSet().add(screen);
			screen.setStockChartPanel(stockChartPanel);
			RepaintStockChartPanelUtil.repaintStockChartPanel(stockChartPanel);
		}
	}

}
